<template>
  <swiper :options="swiperOption">
    <swiper-slide v-for="(page,index) of pages" :key="index">
      <div class="icons">
        <div class="icon" v-for="(item) of page" :key="item.id">
          <img :src="item.imgUrl" alt>
          <p>{{item.title}}</p>
        </div>
      </div>
    </swiper-slide>
    <!-- Optional controls -->
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</template>
<script>
export default {
  name: "HomeIcons",
  props: {
    icons: {
      type: Array
    }
  },
  computed: {
    pages() {
      let pages = [];
      for (let i = 0; i < this.icons.length / 8; i++) {
        pages[i] = this.icons.slice(8 * i, 8 * (i + 1));
      }
      return pages;
    }
  },
  data() {
    return {
      swiperOption: {
        pagination: {   //翻页图标
          el: ".swiper-pagination"
        }
      }
    };
  }
};
</script>
<style lang="scss" scoped>
.icons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 200px 200px;
  border-bottom: 1px solid #ddd;
}
.icon {
  justify-self: center;
  align-self: center;
  text-align: center;
}
.icon img {
  width: 100px;
  height: 100px;
}
.icon p {
  font-size: 14px;
}
</style>

